import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    defaultActive:sessionStorage.getItem("isactive") || '' ,//菜单高亮的值
    isCollapse:false, //菜单收起关闭
    tabslist:JSON.parse(sessionStorage.getItem("tabslist")) || [{
        menuid: 21,
        icon: 'el-icon-user-solid',
        menuname: '首页',
        url: "/IndexView",
        alwaysShow:true
      }] //面包屑数据
  },
  getters: {
  },
  mutations: {
    SetisCollapse(state){
       state.isCollapse =!state.isCollapse 
    },
    //修改面包屑数据
    SetMenu(state,value){
      //判断添加的数据是否存在
      if(value.menuname != '首页'){
        const index = state.tabslist.findIndex(item => item.menuname === value.menuname)
        //如果点击的菜单不存在 state.tabslist
        if(index === -1){
           state.tabslist.push(value)
           //增加完面包屑把数据存到本地做持久化储存
           sessionStorage.setItem("tabslist", JSON.stringify(state.tabslist))
        }
      }
    },
    //删除指定面包屑数据
    ClearTag(state,value){
      const index = state.tabslist.findIndex(item => item.menuname === value.menuname)
      state.tabslist.splice(index,1)
    },
    //修改菜单高亮的值
    SetDefaultActive(state,value){
      state.defaultActive = value
      sessionStorage.setItem('isactive', value);
    }
  },
  actions: {
  },
  modules: {
  }
})
